<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .root {
        width: 180px;
        height: 250px;
        margin: 100px auto;
        border: 1px solid black;
        position: relative;
    }

    .root div {
        font-size: 130px;
        text-align: center;
        width: 100%;
    }

    .root ul {
        position: absolute;
        bottom: 10px;
        left: 0;
        list-style: none;
        display: flex;
        width: 100%;
        justify-content: space-around;
        font-size: 20px;
    }
</style>

<body>
    <div class="root">
        <div style="color: blue;">红</div>
        <ul>
            <li style="color: purple;">红</li>
            <li style="color:green">绿</li>
            <li style="color: blue;">蓝</li>
            <li style="color:red">黄</li>
            <li style="color:yellow">紫</li>
        </ul>
    </div>
</body>

</html>
<script>
    var div1 = document.getElementsByTagName("div")[1];
    var liArray = document.getElementsByTagName("li");
    var arr1 = ["红", "绿", "蓝", "黄", "紫"];
    var arr2 = ["red", "green", "blue", "yellow", "purple"];
    for (i = 0; i < liArray.length; i++) {
        // 来保存下标
        liArray[i].sum = i;
        liArray[i].onclick = function () {
            var color1 = div1.style.color;
            console.log(color1);
            var color2 = arr2[this.sum];
            console.log(color2);
            if (color1 == color2) {
                div1.innerText = arr1[Math.floor(Math.random() * 5)];
                div1.style.color = arr2[Math.floor(Math.random() * 5)];
            } else {
                alert("再试试！")
            }
        }
    }
</script>